import requests

from api.ihrm_login_api import iHrmLoginApi


class IhrmEmpApi(object):
    # 添加员工
    @classmethod
    def ihrm_add(cls,login_token,add_data):
        resq = requests.post('http://ihrm-java.itheima.net/api/sys/user',
                             headers={"Content-Type": "application/json", "Authorization": login_token},
                             json=add_data)
        return resq

    # 查询员工
    @classmethod
    def ihrm_search(cls,login_token,emp_id):
         resq = requests.get('http://ihrm-java.itheima.net/api/sys/user/' + emp_id,
                             headers = {"Content-Type":"application/json","Authorization":login_token})
         return resq
    # 修改员工
    @classmethod
    def ihrm_modify(cls,emp_id,login_token,modify_data):
        resq = requests.put('http://ihrm-java.itheima.net/api/sys/user/' + emp_id,
                            headers = {"Content-Type":"application/json","Authorization":login_token},
                            json=modify_data)
        return resq
    # 删除员工
    @classmethod
    def ihrm_delete(cls,emp_id,login_token):
        resq = requests.delete('http://ihrm-java.itheima.net/api/sys/user/' + emp_id,
                               headers = {"Content-Type":"application/json","Authorization":login_token})
        return resq

if __name__ == '__main__':
    # session = requests.Session()
    # login_data = {"mobile":"13800000002","password":"929itheima.CN032@.20250103"}
    # resq = iHrmLoginApi.iHrmlogin(session,login_data)
    # login_token =resq.json().get('data')
    add_data = {"username": "user87655430","mobile": "13947884888","workNumber": "9527890aa"}
    # print(login_token)
    login_token = "7d1bfb87-771b-4b5a-96da-8a98331ff928"
    print('添加员工结果：',IhrmEmpApi.ihrm_add(login_token, add_data).json())

    print('查询员工',IhrmEmpApi.ihrm_search(login_token, "1494919461403222016").json())
    modify_data = {"username":"zhangsan"}
    print('修改员工姓名为zhangsan:',IhrmEmpApi.ihrm_modify("1494919461403222016", login_token, modify_data).json())
    print('删除员工：',IhrmEmpApi.ihrm_delete("1494919461403222016", login_token).json())